package cn.edu.nwpu.warehousemanagement.pojo;

import cn.edu.nwpu.warehousemanagement.constantEnum.FreightStatus;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 货物
 *
 * @author Loadstar
 * @version 1.0
 */
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "freight")
public class Freight extends BaseEntity {

    // 商品ID，关联商品表，不可为空
    @ManyToOne
    @JoinColumn(name = "product_id", nullable = false, foreignKey = @ForeignKey(name = "fk_freight_product"))
    private Product product;

    @ManyToOne
    @JoinColumn(name = "shelf_id", nullable = false, foreignKey = @ForeignKey(name = "fk_freight_shelf"))
    private Shelf shelf;

    // 生产日期
    @Column(name = "production_date")
    private LocalDate productionDate;

    // 过期日期
    @Column(name = "expiration_date")
    private LocalDate expirationDate;


    // 当前状态，默认值为 'in_stock'
    @Enumerated(EnumType.STRING)
    @Column(name = "status", length = 20, columnDefinition = "VARCHAR(20) DEFAULT 'PRE_STOCK'")
    private FreightStatus status;

//    // 数量，需大于 0
//    @Column(name = "quantity")
//    @Check(constraints = "quantity > 0")
//    private Integer quantity;

    // 入库时间，不可为空
    @Column(name = "inbound_time", nullable = false)
    private LocalDateTime inboundTime;

    //箱号
    @Column(name = "box_id", length = 20, nullable = false)
    private String boxId;

}
